home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / rlib / intersecti < prev    next >
Text File  |  1995-01-17  |  794b  |  47 lines

  1. //-------------------------------------------------------------------//
  2. //  intersection
  3.  
  4. //  Syntax:    intersection ( A , B )
  5.  
  6. //  Description:
  7.  
  8. //  Intersection finds the intersection-set of the two vector sets A,
  9. //  and B.
  10.  
  11. //  See Also: complement, set, union
  12.  
  13. //-------------------------------------------------------------------//
  14.  
  15. intersection = function ( A , B )
  16. {
  17.   if(A.nr == 0 || B.nr == 0) 
  18.   {
  19.     return [];
  20.   }
  21.  
  22.   if (min (size (A)) != 1) 
  23.   {
  24.     error ("intersection: 1st arg must be a vector");
  25.   }
  26.  
  27.   if (min (size (B)) != 1) 
  28.   {
  29.     error ("intersection: 2st arg must be a vector");
  30.   }
  31.  
  32.   a = set (A); b = set (B);
  33.   j = 1;
  34.   Int = [];
  35.  
  36.   for (i in 1:b.n)
  37.   {
  38.     tmp = find (b[i] == a);
  39.     if (tmp.n > 0) 
  40.     {
  41.       Int[j] = b[i];
  42.       j++;
  43.     }
  44.   }
  45.   return Int
  46. };
  47.